# {{ ansible_managed }}
# zsh version: {{ zsh_version }}
# antigen version: {{ zsh_antigen_installed_version }}

export TERM="{{ zsh_term }}"
export EDITOR="{{ zsh_editor }}"
export PATH="{{ zsh_path | join(":") }}"

HIST_STAMPS="{{ zsh_hist_stamps }}"
UPDATE_ZSH_DAYS="{{ zsh_update_interval }}"
COMPLETION_WAITING_DOTS="true"

# ADOTDIR="{{ zsh_antigen_path_compat }}"
{% if zsh_shared %}
ANTIGEN_AUTO_CONFIG=false # disable updates
_ANTIGEN_THEME_COMPAT=false # disable theme cache
{% endif %}

ANTIGEN_BUNDLES="{{ zsh_antigen_path_compat }}/bundles"
ANTIGEN_PLUGIN_UPDATE_DAYS="{{ zsh_update_interval }}"
ANTIGEN_SYSTEM_UPDATE_DAYS="{{ zsh_update_interval }}"

{% if zsh_mc_solarized_skin %}export MC_SKIN="$HOME/.mc/lib/mc-solarized/solarized.ini"{% endif %}

source "{{ zsh_antigen_path_compat }}/antigen/antigen.zsh"

antigen use oh-my-zsh

{% set bundles_enabled = [] %}

{% for bundle in zsh_antigen_bundles -%}
    {%- if bundle is mapping -%}
        {% set valid = true -%}
        {% set command_not_exists = [] -%}

        {%- if bundle.when is defined and not bundle.when -%}
            {% set valid = false -%}
        {% endif -%}

        {% if bundle.command is defined -%}
            {% for cmd in zsh_register_commands_exists.results -%}
                {% if cmd.cmd is defined and cmd.rc != 0 and cmd.item.command == bundle.command -%}
                    {% if command_not_exists.append(1) %}{% endif -%}
                {% endif -%}
            {% endfor -%}
        {% endif -%}

        {% if valid and not command_not_exists %}
            {%- if 'zsh-syntax-highlighting' in bundle.name or 'fast-syntax-highlighting' in bundle.name -%}
# will fixed in zsh-autosuggestion v0.4 - https://github.com/zsh-users/zsh-autosuggestions/pull/218
if (( ZSHRC_LOAD_ONCE++ == 0 )); then
    antigen bundle {{ bundle.name }}
fi
{% else -%}
{% if bundles_enabled.append(bundle.name) %}{% endif -%}
antigen bundle {{ bundle.name }}
{% endif -%}
        {% endif -%}
    {%- else -%}
{% if bundles_enabled.append(bundle) %}{% endif -%}
antigen bundle {{ bundle }}
{% endif %}
{% endfor %}

POWERLEVEL9K_INSTALLATION_PATH=$ANTIGEN_BUNDLES/bhilburn/powerlevel9k/powerlevel9k.zsh-theme

antigen theme {{ zsh_antigen_theme }}

antigen apply

###

{% if not zsh_share_history %}
unsetopt share_history
{% endif %}


autoload -Uz copy-earlier-word
zle -N copy-earlier-word

# hotkeys
{% for hotkey in zsh_hotkeys %}
{% if hotkey.hotkey != '' and (hotkey.bundle is not defined or hotkey.bundle in bundles_enabled) %}
bindkey '{{ hotkey.hotkey }}' {{ hotkey.action }}
{% endif %}
{% endfor %}

# aliases
{% for alias in zsh_aliases %}
{% if alias.alias != '' and (alias.bundle is not defined or alias.bundle in bundles_enabled) %}
alias '{{ alias.alias }}'="{{ alias.action }}"
{% endif %}
{% endfor %}

# fzf
export FZF_TMUX=0
export FZF_DEFAULT_OPTS="{{ zsh_fzf_default_opts }}"

# fzf-widgets: fzf-change-reset-dir
{% if zsh_version is version_compare('5.0', '>=') -%}
autoload -Uz chpwd_recent_dirs cdr add-zsh-hook
add-zsh-hook chpwd chpwd_recent_dirs
{% endif %}
declare -p FZF_WIDGETS_OPTS > /dev/null 2>&1 && FZF_WIDGETS_OPTS[insert-history]="{{ zsh_fzf_ctrl_r_opts }}"
declare -p FZF_WIDGET_OPTS > /dev/null 2>&1 && FZF_WIDGET_OPTS[insert-history]="{{ zsh_fzf_ctrl_r_opts }}"

# zsh-autosuggestions
ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE={{ zsh_autosuggestions_max_length }}
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=240" # gray highlight

# powerlevel9k
POWERLEVEL9K_SHORTEN_DIR_LENGTH={{ zsh_powerlevel9k_shorten_dir_length }}
POWERLEVEL9K_STATUS_VERBOSE={{ zsh_powerlevel9k_status_verbose }}

POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=({{ zsh_powerlevel9k_left_prompt | join(" ") }})
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=({{ zsh_powerlevel9k_right_prompt | join(" ") }})
{% if zsh_powerlevel9k_hide_host_on_local and zsh_user != 'root' %}DEFAULT_USER=$USER{% endif %}

POWERLEVEL9K_ALWAYS_SHOW_CONTEXT={{ zsh_powerlevel9k_always_show_context_bool }}
POWERLEVEL9K_ALWAYS_SHOW_USER={{ zsh_powerlevel9k_always_show_user_bool }}

{% if zsh_powerlevel_custom_elements is defined and zsh_powerlevel_custom_elements %}
{% for element in zsh_powerlevel_custom_elements %}
{% set prefix = "POWERLEVEL9K_CUSTOM_" + element.name | upper %}
{{ prefix }}="{{ element.command }}"
{{ prefix }}_BACKGROUND="{{ element.background }}"
{{ prefix }}_FOREGROUND="{{ element.foreground }}"
{% endfor %}
{% endif %}

# https://github.com/bhilburn/powerlevel9k#command_execution_time
POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD="{{ zsh_command_time_min_seconds }}"

POWERLEVEL9K_PROMPT_ON_NEWLINE={{ zsh_powerlevel9k_prompt_on_newline_bool }}
POWERLEVEL9K_RPROMPT_ON_NEWLINE=false
POWERLEVEL9K_PROMPT_ADD_NEWLINE=true

POWERLEVEL9K_CONTEXT_DEFAULT_FOREGROUND="{{ zsh_powerlevel9k_context_default_foreground }}"
POWERLEVEL9K_CONTEXT_DEFAULT_BACKGROUND="{{ zsh_powerlevel9k_context_default_background }}"
POWERLEVEL9K_CONTEXT_REMOTE_FOREGROUND="{{ zsh_powerlevel9k_context_default_foreground }}"
POWERLEVEL9K_CONTEXT_REMOTE_BACKGROUND="{{ zsh_powerlevel9k_context_default_background }}"
POWERLEVEL9K_CONTEXT_ROOT_FOREGROUND="{{ zsh_powerlevel9k_context_root_foreground }}"
POWERLEVEL9K_CONTEXT_ROOT_BACKGROUND="{{ zsh_powerlevel9k_context_root_background }}"

POWERLEVEL9K_DIR_DEFAULT_FOREGROUND="{{ zsh_powerlevel9k_dir_foreground }}"
POWERLEVEL9K_DIR_DEFAULT_BACKGROUND="{{ zsh_powerlevel9k_dir_background }}"
POWERLEVEL9K_DIR_HOME_FOREGROUND="{{ zsh_powerlevel9k_dir_foreground }}"
POWERLEVEL9K_DIR_HOME_BACKGROUND="{{ zsh_powerlevel9k_dir_background }}"
POWERLEVEL9K_DIR_HOME_SUBFOLDER_FOREGROUND="{{ zsh_powerlevel9k_dir_foreground }}"
POWERLEVEL9K_DIR_HOME_SUBFOLDER_BACKGROUND="{{ zsh_powerlevel9k_dir_background }}"

POWERLEVEL9K_VCS_CLEAN_BACKGROUND="{{ zsh_powerlevel9k_vcs_clean_background }}"
POWERLEVEL9K_VCS_MODIFIED_BACKGROUND="{{ zsh_powerlevel9k_vcs_modified_background }}"
POWERLEVEL9K_VCS_UNTRACKED_BACKGROUND="{{ zsh_powerlevel9k_vcs_untracked_background }}"
POWERLEVEL9K_VCS_CLEAN_FOREGROUND="{{ zsh_powerlevel9k_vcs_foreground }}"
POWERLEVEL9K_VCS_MODIFIED_FOREGROUND="{{ zsh_powerlevel9k_vcs_foreground }}"
POWERLEVEL9K_VCS_UNTRACKED_FOREGROUND="{{ zsh_powerlevel9k_vcs_foreground }}"

POWERLEVEL9K_COMMAND_EXECUTION_TIME_FOREGROUND="{{ zsh_powerlevel9k_command_execution_time_foreground }}"
POWERLEVEL9K_COMMAND_EXECUTION_TIME_BACKGROUND="{{ zsh_powerlevel9k_command_execution_time_background }}"

# Aliases
alias suser='su -'

# user configs
[[ -r /etc/zsh/zshrc.local ]] && source /etc/zsh/zshrc.local
[[ -r "$HOME/.zshrc.local" ]] && source "$HOME/.zshrc.local"
